public class Dom21 {
    //加锁的第二种情况
    //
    public static void main(String[] args) throws InterruptedException {
        Object local1=new Object();
        Object local2=new Object();
        Thread t1=new Thread(()->{
           synchronized (local1){
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               synchronized (local2){
                   //t1线程获得第二线程
                   System.out.println("t1线程获得t2线程");
               }
           }
        });
        Thread t2=new Thread(()->{
            synchronized (local2){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (local1){
                    //t2线程获得t1线程
                    System.out.println("t2线程获得了t1线程");
                }
            }

        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
    }
}
